﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MovieRental.XmlDataProviderCore;
using MovieRental.DataInterfaces;
using MovieRental.Entities;
using MovieRental.GeneralDataExceptions;

namespace MovieRental.XmlRepositoryLibrary
{
    public class XmlTemporaryDiscountRepository : XmlRepository<TemporaryDiscountInfo>, ITemporaryDiscountRepository
    {
        public XmlTemporaryDiscountRepository(XmlDataProvider provider) : base(provider)
        {
        }

        public TemporaryDiscountInfo Load(Guid id)
        {
            using (var context = CreateContext())
            {
                var set = context.GetAllForType(typeof(TemporaryDiscountInfo)).Select(x => (TemporaryDiscountInfo)x);
                try
                {
                    return set.Single(x => x.Id == id);
                }
                catch (Exception ex)
                {
                    throw new ItemNotFoundException(id.ToString(), ex);
                }
            }
        }

        public void Delete(Guid id)
        {
            TemporaryDiscountInfo temporaryDiscount = new TemporaryDiscountInfo(id);
            Delete(temporaryDiscount);
        }

    }
}
